#pragma once

#include "mccommonapi.h"
#include "XMLElement.h"
#include "accesscount.h"

#include <xercesc/dom/DOM.hpp>

namespace MCCommon
{

class MCAPI XMLDocument : public XMLElement
{
public:

    /**
     * Constructor.
     * 
     */   
    XMLDocument
    (
        xercesc::DOMDocument* pDomDoc,
        xercesc::DOMLSParser* pDomParser = 0 
     );

    /**
     * Destructor.
     * 
     */
    virtual ~XMLDocument(); 
   
    /**
     * Copy constructor.
     * 
     */
    XMLDocument
    (
        const XMLDocument& document
    );
    
    /**
     * Assign operator.
     * 
     */
    XMLDocument& operator = 
    (
        const XMLDocument& document
    );    

    /**
     * Start up XML service. 
     * Note: it MUST be called before any XML operation.
     * 
     */
    static void StartUp();

    /**
     * Shut down XML service. 
     * Note: it must be called before the application quit. 
     * 
     */
    static void ShutDown();

    /**
     * Load XML from a file.
     * 
     */
    static XMLDocument LoadFromFile
    (
        const std::string& fileName
    );
    
    /**
     * Load XML from a string.
     * 
     */
    static XMLDocument LoadFromString
    (
        const std::string& str
    );

    /**
     * Create root element.
     * 
     */
    static XMLDocument CreateRootElement
    (
        const std::string& rootEleName
    );

private:   
    /**
     * Release all resource.
     * 
     */
    void Release();    

private:
    
    // The DOM document.
    xercesc::DOMDocument* fDomDocument; 

    // DOM parser.
    xercesc::DOMLSParser *fDomParser;

    // Access count.
    AccessCount fAccCount;
};

} // end of namespace.
